<?php
$adm_menu = "1";

include("config.php");
if (!isset($_SESSION["auser"]) || $_SESSION["auser"] == "" || $_SESSION['agroup'] != "WEB_ADMIN") header('Location: index.php');


$db_www = new DB($server_username,$server_pass,$server_db,$server,$driver);
$db_rdata = new DB($rdata_server_username,$rdata_server_pass,$rdata_server_db,$rdata_server,$rdata_driver);
if (!$db_rdata->isConnected()) {	
	die("Klientų aptarnavimo sistema laikinai neveikia(rdata).");
}	

include("header.php");
include("menu.php");


echo "<table class='innercont' cellspacing='0' cellpadding='10' border='0'>";
echo "<tr><td class='leftcol2'>";
echo "<table cellspacing=\"0\" cellpadding=\"5\" class=\"params\" style=\"\"><tbody><tr><td style=\"text-align:center;\"><a id=\"editButton\" href=\"terminal.php\" class=\"card3\">Naujas aparatas</a></td></tr></tbody></table>";
echo "<br><table cellspacing=\"0\" cellpadding=\"5\" class=\"params\" style=\"\"><tbody><tr><td style=\"text-align:center;\"><a id=\"editButton\" href=\"roles.php\" class=\"card3\">Aparatų rolės</a></td></tr></tbody></table>";
echo "</td>";
echo "<td class='centercol'>";
?>
<script>
var id = null;

function modVouncher(iid){
    id = iid;
	window.location='terminal.php?uid='+iid;
}

</script>
<?php
	$ns = $db_rdata->returnList($terminals_query);
	echo '<table class="innercont2" cellspacing="0" cellpadding="2"><tr><th>Aparato Id</th><th>Pavadinimas</th><th>Padalinys</th><th>Aparato rolė</th><th>Paskutinis perkeltas Z</th><th>Matomas apžvalgoje</th></tr>';

	foreach ($ns as $degaline) {
		

		$pad = $db_www->returnInfo("select I24_KODAS_IS,I24_PAR_TXT15 from I24_RYS where I24_KODAS_KK='".addslashes_mssql($degaline["AparatoID"])."'");
			$zeto = "";
			$pd = "";
			if (!empty($pad)) {
				$zeto = $pad["I24_PAR_TXT15"];
				$pd = $pad["I24_KODAS_IS"];
			}
		
	$click = "onclick=\"modVouncher('".$degaline["AparatoID"]."');\" class='click'";
	
		echo "<tr $click >";
		echo "<td >".$degaline["AparatoID"]."</td>";
		echo "<td>".@iconv('windows-1257','UTF-8',$degaline["AparatoPavadinimas"])."</td>";
		echo "<td >".$pd."</td>";
		echo "<td >".$degaline["role_id"]."</td>";
		echo "<td style='text-align:center;'>".$zeto."</td>";
		echo "<td style='text-align:center;'>";
		if ($degaline["apzvalga"]==1) echo "Taip"; else echo "Ne";
		echo "</td>";

		echo "</tr>";
	}
	
	echo "</table>";
	


	
	echo "</td></tr></table>";

include("footer.php");
?>